<template>
  <div class="">
    <header>
      <van-nav-bar title="个人中心" :border="false"></van-nav-bar>
      <div class="mine" @click="$router.push('/personal')">
        <img :src="$publicObj.urlImg(userInfo.image)" alt="" />
        <div class="person">
          <div class="top">
            <p>{{ userInfo.nickname }}</p>
            <span v-if="userInfo.certification == 1">已实名</span>
            <span v-else>未实名</span>
          </div>
          <div class="bottom">
            <p>{{ userInfo.phone || "" }}</p>
            <span class="users" v-if="userInfo.deadType == 0">未认证用户</span>
            <span class="users" v-else-if="userInfo.deadType == 1"
              >免费用户</span
            >
            <span class="users" v-else-if="userInfo.deadType == 2">周用户</span>
            <span class="users" v-else-if="userInfo.deadType == 3">月用户</span>
            <span class="users" v-else-if="userInfo.deadType == 4">年用户</span>
          </div>
        </div>
        <van-icon name="arrow" color="#fff" />
      </div>
      <div class="title">
        <div class="item">
          <p>{{ history[0].Share || 0 }}</p>
          <p>已转发</p>
        </div>
        <div class="item">
          <p>{{ history[1].Share || 0 }}</p>
          <p>已阅读</p>
        </div>
        <div class="item">
          <p>{{ IncomeObj.forward || 0 }}</p>
          <p>今日转发</p>
        </div>
        <div class="item">
          <p>{{ IncomeObj.read || 0 }}</p>
          <p>今日阅读</p>
        </div>
      </div>
      <div class="earnings">
        <van-cell title="我的收益" is-link value="查看收益" to="/wallet" />
        <div class="bottom" @click="$router.push('/wallet')">
          <div class="item">
            <span>{{ IncomeObj.historyIncome || 0 }}</span>
            <span>推广收益</span>
          </div>
          <div class="item">
            <span>{{ IncomeObj.earningsBalance || 0 }}</span>
            <span>文案收益</span>
          </div>
          <div class="item">
            <span>{{ IncomeObj.dayIncome || 0 }}</span>
            <span>下级收益</span>
          </div>
          <div class="item">
            <span>{{ IncomeObj.sumBalance || 0 }}</span>
            <span>总收益</span>
          </div>
        </div>
      </div>
    </header>
    <main>
      <van-cell-group>
        <van-cell
          title="我的钱包"
          :icon="require('../../assets/images/mine/min_wallet.png')"
          is-link
          to="/wallet"
        />
        <van-cell
          title="我的订单"
          :icon="require('../../assets/images/mine/mine_order.png')"
          is-link
          @click="goOrder"
        />
        <van-cell
          title="已完成任务"
          :icon="require('../../assets/images/mine/mine_finish.png')"
          is-link
          to="/taskFinish"
        />
        <van-cell
          title="推广中任务"
          :icon="require('../../assets/images/mine/mine_push.png')"
          is-link
          @click="goExtendTask"
        />
        <van-cell
          title="已上传文案库"
          :icon="require('../../assets/images/mine/mine_astore.png')"
          is-link
          @click="$router.push('/articleMaterial?type=1')"
        />
        <van-cell
          title="浏览记录"
          :icon="require('../../assets/images/mine/mine_liulan.png')"
          is-link
          @click="$router.push('/browsinghistory')"
        />
        <van-cell
          title="表单信息"
          :icon="require('../../assets/images/mine/mine_form.png')"
          is-link
          @click="goForm"
        />
        <van-cell
          title="管理员设置"
          :icon="require('../../assets/images/mine/mine_admin.png')"
          is-link
          @click="goAdmin"
        />
        <van-cell
          title="绑定企业账号"
          :icon="require('../../assets/images/mine/mine_con.png')"
          is-link
          @click="goBoundFirm"
        />
        <van-cell
          title="注册认证"
          :icon="require('../../assets/images/mine/mine_login.png')"
          is-link
          @click="goLogin"
        />
        <van-cell
          title="帮助中心"
          :icon="require('../../assets/images/mine/mine_help.png')"
          is-link
          @click="$router.push('/help')"
        />
      </van-cell-group>

      <h3>我的奖励</h3>
      <p>立即分享文章赚钱，联系客服，申请代理。</p>
    </main>
    <div class="poster">
      <img src="../../assets/images/mine/head_poster.png" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  name: "mine",
  data() {
    return {
      userInfo: {}, //个人信息
      IncomeObj: {}, //个人中心数据
      isPower: 2, //默认普通用户
      info: "",
      // today: [{ Share: 0 }, { Share: 0 }], //今日
      history: [{ Share: 0 }, { Share: 0 }], //历史
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    document.querySelector("html").style.backgroundColor = "#f3f5f7";
    document.querySelector("body").style.backgroundColor = "#f3f5f7";
  },
  //生命周期 - 挂载完成（访问DOM元素）
  async mounted() {
    await this.getUser();
    await this.isCustomer();
    this.getMyIncome();
  },
  methods: {
    //去绑定企业
    goBoundFirm() {
      if (this.isPower == 1) {
        this.$router.push("/boundFirm?bind=1");
      } else {
        this.$router.push("/boundFirm");
      }
    },
    //去设置管理员
    goAdmin() {
      if (this.isPower != 1) return this.$toast("您的权限不足，无法查看！");
      this.$router.push("/admin");
    },
    //去注册
    goLogin() {
      if (this.isPower == 1) {
        return this.$router.push("/mineInstructions");
      }
      if (this.isPower == 3 && this.info != " ") {
        return this.$router.push("/mineInstructions");
      }

      this.$router.push("/mineLogin");
    },
    //去订单
    goOrder() {
      // if (this.isPower != 1) return this.$toast("您的权限不足，无法查看！");
      this.$router.push("/order");
    },
    //去表单信息
    goForm() {
      if (this.isPower != 1) return this.$toast("您的权限不足，无法查看！");
      this.$router.push("/form");
    },
    //去推广任务
    goExtendTask() {
      // if (!this.isPower) return this.$toast("您的权限不足，无法查看！");
      this.$router.push("/extendTask");
    },
    //获取用户信息
    async getUser() {
      // 获取个人信息
      await this.$store.dispatch("updateUserInfo");
      this.userInfo = this.$store.state.userInfo;
    },
    //获取个人中心数据
    async getMyIncome() {
      let res = await this.$api.getMyIncome({ userId: this.userInfo.id });
      if (res.code !== 0) return;
      this.IncomeObj = res.data;
      this.history = res.history || [{ Share: 0 }, { Share: 0 }];
      // this.today = res.today || [{ Share: 0 }, { Share: 0 }];
    },
    //判断是否有权限创建
    async isCustomer() {
      let userWxData = JSON.parse(sessionStorage.getItem("userWxData"));
      let account = sessionStorage.getItem("agentId");
      let res = await this.$api.isCustomer({
        openId: userWxData.openid,
        account,
        id: this.$store.state.userInfo.id,
        phone: this.$store.state.userInfo.phone,
      });
      this.isPower = res.data;
      this.info = res.info;
    },
  },
};
</script>
<style scoped lang="less">
/* @import url(); 引入css类 */
.van-cell-group {
  margin-top: 15px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
  .van-cell {
    &:first-of-type {
      border-radius: 10px 10px 0 0;
    }
    &:last-of-type {
      border-radius: 0 0 10px 10px;
    }
  }
}
header {
  background: url("../../assets/images/mine/head_bg.png") no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 285px;
  position: relative;
  /deep/ .van-nav-bar {
    background-color: rgba(0, 0, 0, 0);
    .van-nav-bar__content {
      border-bottom: 0.5px solid #e4e4e493;
    }
    .van-nav-bar__title {
      color: #fff !important;
    }
  }
  .mine {
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    img {
      width: 70px;
      height: 70px;
      border-radius: 50%;
    }
    .person {
      margin-left: 20px;
      flex: 1;
      height: 70px;
      color: #ffffff;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: flex-start;
      padding: 10px 0;
      .top {
        display: flex;
        align-items: center;
        p {
          width: 150px;
          font-size: 16px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        span {
          margin-left: 10px;
          display: flex;
          justify-content: center;
          align-items: center;
          width: 44px;
          height: 15px;
          background: rgba(250, 250, 250, 0.6);
          font-size: 11px;
          font-weight: 700;
          color: #637edf;
          border-radius: 4px;
        }
      }
      .bottom {
        display: flex;
        justify-content: space-between;
        width: 100%;
        font-size: 17px;
        padding-right: 20px;
        .users {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 68px;
          height: 18px;
          background: linear-gradient(180deg, #f8e14b, #fc8701);
          border-radius: 9px;
          font-size: 12px;
          color: #ffffff;
          &:nth-of-type(2) {
            background: linear-gradient(180deg, #72f5a2, #00b0ff);
          }
          &:nth-of-type(3) {
            background: linear-gradient(180deg, #f01eff 0%, #1900ff 100%);
          }
          &:nth-of-type(4) {
            background: linear-gradient(180deg, #38bafe, #004af6);
          }
          &:nth-of-type(5) {
            background: linear-gradient(180deg, #ff9e1e, #ff3400);
          }
        }
      }
    }
  }
  .title {
    color: #fff;
    margin-top: 25px;
    display: flex;
    .item {
      flex: 1;
      text-align: center;
      height: 40px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      p {
        font-size: 18px;
        &:last-of-type {
          font-size: 11px;
        }
      }
      &:nth-of-type(n + 2) {
        border-left: 1px solid #fff;
      }
    }
  }
  .earnings {
    position: absolute;
    bottom: -68px;
    left: 15px;
    width: 345px;
    height: 128px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0px 2px 3px 0px rgba(0, 0, 0, 0.16);
    .van-cell {
      border-radius: 15px 15px 0 0;
    }
    .bottom {
      height: 84px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      border-radius: 0 0 15px 15px;
      .item {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        height: 100%;
        box-sizing: border-box;
        padding: 20px 0;
        span {
          font-size: 15px;
          &:last-of-type {
            font-size: 12px;
          }
        }
      }
    }
  }
}
main {
  padding: 70px 15px 0;
  h3 {
    font-size: 16px;
    color: #333333;
    margin: 27px 0 15px 0;
  }
  .task {
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 10px;
    height: 75px;
    .item {
      height: 100%;
      width: 48%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
  }
  .push {
    display: flex;
    .item {
      font-size: 14px;
      text-align: center;
      img {
        width: 82px;
        height: 82px;
      }
    }
  }
  p {
    text-align: center;
    font-size: 12px;
    color: #333333;
  }
  /deep/ .van-cell__title,
  .van-cell__value {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    padding-left: 5px;
  }
}
.poster {
  margin-top: 10px;
  width: 100%;
  height: 150px;
  margin-bottom: 50px;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
